package com.inno.game.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.inno.game.bean.User;


import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;

public class JSONHelper {
	public static Map parserMap(Object obj){
		Map map=new HashMap();
		JSONObject json=JSONObject.fromObject(obj);
		Iterator keys=json.keys();
		while(keys.hasNext()){
			String key=(String) keys.next();
			Object value = json.get(key);
			System.out.println(key+":"+value);
			if(JSONUtils.mayBeJSON(String.valueOf(value)))
			{
				map.put(key, parserMap(value));
			}
			else {
				map.put(key, value);
			}
		}
		return map;
	}
	public static Object parserBean(Object obj){
		Map map=new HashMap();
		JSONObject json=JSONObject.fromObject(obj);
		return JSONObject.toBean(json, User.class);
	}
}
